package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.entity.brand.Brand;
import com.atguigu.spzx.model.entity.category.CategoryBrand;
import com.atguigu.spzx.model.vo.category.CategoryBrandVo;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * title:
 * author: zgl
 * date: 2024/1/5
 * description：
 */
@RestController
@RequestMapping("/admin/product/categoryBrand")
@Tag(name = "分类品牌管理模块")
public class CategoryBrandController {
    @Autowired
    private CategoryBrandService categoryBrandService;

    @GetMapping("/getBrandByCategoryId/{categoryId}")
    @Operation(summary = "分类id查询品牌接口")
    public Result getBrandByCategoryId(@PathVariable Long categoryId) {
        List<Brand> brandList = categoryBrandService.getBrandByCategoryId(categoryId);
        return Result.ok(brandList);
    }

    @GetMapping("/getCategoryBrand/{id}")
    @Operation(summary = "id查询分类品牌接口")
    public Result getCategoryBrand(@PathVariable Long id) {
        CategoryBrand categoryBrand = categoryBrandService.getCategoryBrand(id);
        return Result.ok(categoryBrand);
    }

    @GetMapping("/list/{pageNum}/{pageSize}")
    @Operation(summary = "查询分类品牌接口")
    public Result list(
            @PathVariable Integer pageNum,
            @PathVariable Integer pageSize,
            CategoryBrand categoryBrand) {
        PageInfo<CategoryBrandVo> pageInfo = categoryBrandService.list(pageNum, pageSize, categoryBrand);
        return Result.ok(pageInfo);
    }

    @DeleteMapping("/deleteCategoryBrand/{id}")
    @Operation(summary = "删除分类品牌接口")
    public Result deleteCategoryBrand(@PathVariable Long id) {
        categoryBrandService.deleteCategoryBrand(id);
        return Result.ok();
    }


    @PostMapping("/saveCategoryBrand")
    @Operation(summary = "添加分类品牌接口")
    public Result saveCategoryBrand(@RequestBody CategoryBrand categoryBrand) {
        categoryBrandService.saveCategoryBrand(categoryBrand);
        return Result.ok();
    }


    @PutMapping("/updateCategoryBrand")
    @Operation(summary = "修改品牌接口")
    public Result updateCategoryBrand(@RequestBody CategoryBrand categoryBrand) {
        categoryBrandService.updateCategoryBrand(categoryBrand);
        return Result.ok();
    }
}
